package com.szzg10.thinking.chapter11;

import java.util.Iterator;

public class IterableClass implements Iterable<String> {

	protected String[] words = "And that is how we know the Earth to be banana-shaped.".split(" ");
	
	public static void main(String[] args) {
		IterableClass iterableClass = new IterableClass();
		for(String element: iterableClass) {
			System.out.println(element);
		}
	}
	
	@Override
	public Iterator<String> iterator() {
		return new Iterator<String>() {
			private int next = 0;
			
			@Override
			public boolean hasNext() {
				return next < words.length;
			}

			@Override
			public String next() {
				return words[next++];
			}

			@Override
			public void remove() {
				throw new UnsupportedOperationException();
			}
		};
	}

}
